package com.hnevc.ormlitedemo.utlis;

import android.content.Context;

import com.hnevc.ormlitedemo.entity.RechargeRecord;
import com.j256.ormlite.dao.Dao;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by Administrator on 2017/12/31.
 */

public class RechargeRecordDao {
    private Dao<RechargeRecord,Integer> dao;
    public RechargeRecordDao(Context context){
        try {
            dao = OpenHelper.getHelper(context).getDao(RechargeRecord.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public int addRechargeRecord(RechargeRecord record){
        try {
            return dao.create(record);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return -1;
    }
    public List<RechargeRecord> queryForAll(){
        List<RechargeRecord> rechargeRecords = null;
        try {
            //rechargeRecords = dao.queryForAll();
            rechargeRecords =  dao.queryBuilder().orderBy("id",false).query();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return  rechargeRecords;
    }


}
